package com.lemon.play.goai.posjudge;

import android.graphics.Point;

public class Spot implements Cloneable {
	
	public Spot(){
		this(0,0,null,PREPARED);
	}

	public Spot(Point location, Boolean camp) {
		this(location.x, location.y, camp, PREPARED);
	}

	public Spot(int x, int y, Boolean camp) {
		this(x, y, camp, PREPARED);
	}

	public Spot(int x, int y, Boolean camp, int order) {
		if (x < 0 || x > 18 || y < 0 || y > 18)
			throw new IllegalArgumentException(
					"The value of x and y must be [0,19)!");
		this.x = x;
		this.y = y;
		this.camp = camp;
		this.order = order;
	}

	public Point getLocation() {
		return new Point(x, y);
	}

	public Boolean getCamp() {
		return camp;
	}

	public int getX() {
		return x;
	}

	public int getY() {
		return y;
	}

	public int getOrder() {
		return order;
	}

	public void setLocation(Point location) {
		this.x = location.x;
		this.y = location.y;
	}

	public void setX(int x) {
		this.x = x;
	}

	public void setY(int y) {
		this.y = y;
	}

	public void setCamp(Boolean camp) {
		this.camp = camp;
	}

	public void setOrder(int order) {
		this.order = order;
	}

	public void setInfo(String info) {
		this.info = info;
	}

	public String getInfo() {
		return this.info;
	}

	@Override
	public boolean equals(Object o) {
		if(o==null)
			return false;
		if (o.getClass().equals(Spot.class)) {
			Spot spot = (Spot) o;
			if (spot.getCamp() == this.camp && spot.getX() == this.x
					&& spot.getY() == this.y && spot.getOrder() == this.order) {
				return true;
			}
		}
		return false;
	}

	@Override
	public int hashCode() {
		int hash = 0;
		if (camp == null) {
			hash = 0x00000000;
		} else if (camp) {
			hash = 0x00080000;
		} else {
			hash = 0x00100000;
		}
		hash += order;
		hash += (y * 19 + x) << 10;
		return hash;
	}
	
	@Override
	public String toString(){
		if(order==PASS){
			if(camp==null)
				return "[ PASS ]";
			if(camp==BLACK)
				return "[ BLACK, PASS ]";
			else
				return "[ WHITE, PASS ]";
		}
		StringBuilder builder=new StringBuilder();
		builder.append("[ X:");
		builder.append(x);
		builder.append(", Y:");
		builder.append(y);
		if(camp==null)
			builder.append(", NON-CAMP");
		else if(camp==BLACK)
			builder.append(", BLACK");
		else
			builder.append(", WHITE");
		builder.append(", ORDER:");
		builder.append(order);
		builder.append(" ]");
		return builder.toString();
	}

	@Override
	public Object clone() {
		Spot newSpot = new Spot(this.x, this.y, this.camp, this.order);
		return newSpot;
	}

	private int x;
	private int y;
	private Boolean camp;
	private int order;
	private String info;

	public static final int PREPARED = 0;
	public static final int PASS = -1;
	public static final Boolean BLACK = Boolean.TRUE;
	public static final Boolean WHITE = Boolean.FALSE;
	public static final Boolean NONE = null;
	public static final Spot PASS_BLACK = new Spot(0, 0, BLACK, PASS);
	public static final Spot PASS_WHITE = new Spot(0, 0, WHITE, PASS);
}